﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI;
using rossisdead.Mvc.Detergent;
using DetergentDemoSite.Models;

namespace DetergentDemoSite.Controllers
{
    public class AnimalController : Controller
    {
        [HttpGet, OutputCache(Duration = 300, Location = OutputCacheLocation.Client, VaryByParam = "SelectedAnimalType")]
        public CascadingActionResult GetAnimalsByAnimalType(AnimalTypes SelectedAnimalType)
        {
            var results = new List<Animal>();
            switch (SelectedAnimalType)
            {
                case AnimalTypes.Adorable:
                    results.Add(new Animal { AnimalId = 1, Name = "Kittens", AnimalType = AnimalTypes.Adorable });
                    results.Add(new Animal { AnimalId = 2, Name = "Puppies", AnimalType= AnimalTypes.Adorable });
                    results.Add(new Animal { AnimalId = 3, Name = "Aligators", AnimalType= AnimalTypes.Adorable });
                    break;

                case AnimalTypes.NotSoAdorable:
                    results.Add(new Animal { AnimalId = 4, Name = "Goats", AnimalType = AnimalTypes.NotSoAdorable });
                    results.Add(new Animal { AnimalId = 4, Name = "Bats", AnimalType = AnimalTypes.NotSoAdorable });
                    break;
            }

            return new CascadingActionResult { Data = results, TextField = "Name", ValueField = "AnimalId", JsonRequestBehavior = JsonRequestBehavior.AllowGet };

        }
    }
}
